// directives/permission.ts
// import type { App } from 'vue'

// // 权限类型定义
// interface Permission {
//   code: string;
//   name: string;
// }

// // 模拟权限数据 - 实际从store或API获取
// const permissionList: Permission[] = [
//   { code: 'user:add', name: '新增用户' },
//   { code: 'user:edit', name: '编辑用户' },
//   { code: 'user:delete', name: '删除用户' }
// ]

// export const permissionDirective = {
//   mounted(el: HTMLElement, binding: any) {
//     const { value } = binding
//     const hasPermission = permissionList.some(permission => permission.code === value)
    
//     if (!hasPermission) {
//       el.parentNode?.removeChild(el)
//     }
//   }
// }


import type { App } from 'vue'
import { usePermissionStore } from '../stores/permission'

export const permissionDirective = {
  mounted(el: HTMLElement, binding: any) {
    const store = usePermissionStore()
    const hasPermission = store.hasPermission(binding.value)
    
    if (!hasPermission) {
      el.parentNode?.removeChild(el)
    }
  }
}

export const install = (app: App) => {
  app.directive('permission', permissionDirective)
}